import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class NGuessNumberTest {
        @Test
        void generateAnswer() {
            //检查答案数字数量是否为4，其中是否无重复数字，以及数字是否都在0-9之间。
            int quantity = 4;
            NGuessNumber nGuessNumber = new NGuessNumber();
            assertEquals(quantity, nGuessNumber.generateAnswer().length);
            System.out.println("数字数量为4，正确");
            int num[] = nGuessNumber.generateAnswer();
            boolean repeat = false;
            int range = 0;
            for (int i = 0; i < quantity; i++) {
                if (num[i] >= 0 && num[i] <= 9) {
                    range = 1;
                } else {
                    range = 0;
                }
                for (int j = 0; j <= i; j++) {
                    if (i != j) {
                        if (num[i] == num[j]) {
                            repeat = false;
                        } else {
                            repeat = true;
                        }
                    }
                }
            }
            assertEquals(true, repeat);
            System.out.println("无重复数字，正确");
            assertEquals(1, range);
            System.out.println("数字都在0-9之间，正确");
        }
}
class getPlayerInputTest{
    @Test
    void getPlayerInput() {
        int numsize = 4;
        NGuessNumber nGuessNumber = new NGuessNumber();
        assertEquals(numsize,nGuessNumber.guesslist.length);
        System.out.println("用户输入的数字数量为4，正确");
    }
}
class compareGuessAnswer{
    @Test
    void compareGuessAnswer() {
        NGuessNumber nGuessNumber = new NGuessNumber();

        int testguess []= nGuessNumber.guesslist;
        int testnum []= nGuessNumber.generateAnswer();
        //System.out.println(Arrays.toString(testguess));
        int a_num = 0;
        int b_num = 0;
        for (int i = 0; i < testnum.length; i++) {
            for (int j=0; j < testnum.length; j++){
                if(i!=j){
                    if(testnum[i]==testguess[j]){
                        b_num++;
                    }
                }else{
                    if(testnum[i]==testguess[j]){
                        a_num++;
                    }
                }

            }
        }
        String s = a_num+"A"+b_num+"B\n"+"A表示存在且位置正确的数字个数，B表示存在且位置不正确的数字个数！\n"+"如：1A2B,表示你猜测的四个数字有3个是对的，有一个位置对，两个位置不对。";
        assertEquals(s,nGuessNumber.compareGuessAnswer());
        System.out.println("测试比较玩家猜测和答案后，返回的提示信息，正确");
    }
}
class isWin{
    @Test
    void isWin() {
        NGuessNumber nGuessNumber = new NGuessNumber();

        if(nGuessNumber.isWin()==true){
            assertEquals(true,nGuessNumber.isWin());
            System.out.println("获胜");
        }else{
            assertEquals(false,nGuessNumber.isWin());
            System.out.println("失败");
        }
    }
}